package com.sgu6.sgu6_machine.ui.fragment.dialog;

import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.sgu6.middleware.manager.ThreadManager;
import com.sgu6.middleware.util.HttpUtil;
import com.sgu6.sgu6_machine.R;
import com.sgu6.sgu6_machine.adapter.MemberRechargeAdapter;
import com.sgu6.sgu6_machine.base.BaseF;
import com.sgu6.sgu6_machine.common.Constant;
import com.sgu6.sgu6_machine.config.MachineConfig;
import com.sgu6.sgu6_machine.container.MachineContainer;
import com.sgu6.sgu6_machine.dto.MemberCardInfoDto;
import com.sgu6.sgu6_machine.dto.SaleRulesDto;
import com.sgu6.sgu6_machine.params.RechargeParam;
import com.sgu6.sgu6_machine.presenter.MachineP;
import com.sgu6.sgu6_machine.util.QRCodeUtil;
import com.wang.avi.AVLoadingIndicatorView;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Timer;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MemberRechargeF extends BaseF {

    @BindView(R.id.iv_bind)
    ImageView ivBind;
    @BindView(R.id.tv_desp)
    TextView tvDesc;


    public static MemberRechargeF newInstance(String params) {
        return new MemberRechargeF();
    }


    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (!EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().register(this);
        }
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.fragment_dialog_recharge, container, false);
        unbinder = ButterKnife.bind(this, v);



        return v;
    }

    private void initUI() {

    }

    // TODO: 2020-09-25  如果查询失败，则隐藏查询中状态，提示未查询到，请重新输入
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMemberCardInfoEvent(MemberCardInfoDto memberCardInfoDto) {
        tvDesc.setVisibility(View.VISIBLE);
        ivBind.setVisibility(View.VISIBLE);
        String content = "http://rest-api.sgu6.com/wxlogin?type=bindCard&merchantId=%s&cardCode=%s";
        String url = String.format(content, memberCardInfoDto.getMerchantId(), memberCardInfoDto.getCardCode());
        Bitmap bp = QRCodeUtil.createQRCodeBitmap(url, 240, 240);
        ivBind.setImageBitmap(bp);
    }
    @Override
    public void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
        unbinder.unbind();
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
    }

    public void updateCardNo(String cardNo) {
//        this.cardNo = cardNo;
    }

}
